
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using Csla.Validation;

namespace SariturIntranetLibrary.Grupos
{
    [Serializable()]
    public class GrupoChildInfo : Csla.ReadOnlyBase<GrupoChildInfo>
    {

        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _nomeDoGrupo = string.Empty;

        [System.ComponentModel.DataObjectField(true, false)]
        public Guid Id
        {
            get
            {
                CanReadProperty("Id", true);
                return _id;
            }
        }

        public string NomeDoGrupo
        {
            get
            {
                CanReadProperty("NomeDoGrupo", true);
                return _nomeDoGrupo;
            }
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in GrupoChildInfo
            //AuthorizationRules.AllowRead("Id", "GrupoChildInfoReadGroup");
            //AuthorizationRules.AllowRead("NomeDoGrupo", "GrupoChildInfoReadGroup");

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static GrupoChildInfo GetGrupoChildInfo(SafeDataReader dr)
        {
            return new GrupoChildInfo(dr);
        }

        private GrupoChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods


        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = dr.GetGuid("Id");
            _nomeDoGrupo = dr.GetString("NomeDoGrupo");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
